package com.transaction.simulate.service.impl;

import com.transaction.common.base.PageInfo;
import com.transaction.common.util.PageUtil;
import com.transaction.simulate.mapper.FundRateMapper;
import com.transaction.simulate.model.dto.FundRate;
import com.transaction.simulate.service.FundRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
public class FundRateServiceImpl implements FundRateService {

    @Autowired
    private FundRateMapper fundRateMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,rollbackFor = Exception.class)
    public List<FundRate> getFundRateList(FundRate fundRate, PageInfo pageInfo) {
        PageUtil.StartPage(pageInfo);
        return fundRateMapper.getFundRateList(fundRate);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void addFundRate(FundRate fundRate) {
        fundRate.setFundRate(fundRate.getFundRate().divide(new BigDecimal(100)));
        fundRateMapper.addFundRate(fundRate);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void deleteFundRate(FundRate fundRate) {
        fundRateMapper.deleteFundRate(fundRate);
    }
}
